package com.epalmpay.controller.apiXdlPay;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.apiXdlPay.IApiXdlService;
import com.epalmpay.util.Response;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created by Administrator on 2018/4/20.
 */
@Controller
@RequestMapping(value="/api/xdl")
public class XdlApiController extends BaseController {

    @Resource
    private IApiXdlService apiXdlService;

    @RequestMapping(value = "/goPay", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response goPay(String memberId,String groupId,String mchntid,String termid,String amount,String total_amount,
                          String auth_code,String paychannel,String goodsdesc,String tradeno) throws Exception {
        logBefore(logger, "新大陆支付");
        try {
            Response response = apiXdlService.goPay(memberId,groupId,mchntid,termid,amount,total_amount,auth_code,paychannel,goodsdesc,tradeno);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    @RequestMapping(value = "/goQueryOrderNo", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response goQueryOrderNo(String mchntid,String termid,String tradeno) throws Exception {
        logBefore(logger, "新大陆支付");
        try {
            Response response = apiXdlService.goQueryOrderNo(mchntid,termid,tradeno);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }

    @RequestMapping(value = "/scanbarrefund", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Response scanbarrefund(String mchntid,String termid,String tradeno,String txnAmt) throws Exception {
        logBefore(logger, "新大陆支付");
        try {
            Response response = apiXdlService.scanbarrefund(mchntid,termid,tradeno,txnAmt);
            return response;
        } catch (ApplicationException ae) {
            logger.error(ae);
            ae.printStackTrace();
            return Response.getError(ae.errMsg);
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
            return Response.getError("服务器异常");
        }
    }
}
